package com.pe.cineplanet.proyectocine.repository.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.pe.cineplanet.proyectocine.domain.Local;
import com.pe.cineplanet.proyectocine.repository.LocalRepository;
 
@Repository
public class LocalRepositoryHibernate extends HibernateDaoSupport 
implements LocalRepository{

	//constructor
	@Autowired
	public LocalRepositoryHibernate(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}
	
	public List<Local> obtenerLocales() {
		return getHibernateTemplate().find("from Local");   
	}

	public Local obtenerLocal(int id_Local) {
		return (Local) getSession().createQuery("from Local u where u.id_Local=?").setInteger(0, id_Local).uniqueResult();
	}

	public void grabarLocal(Local obj) {
		getHibernateTemplate().saveOrUpdate(obj);
		
	}

	public void removerLocal(int id_Local) {
		Local obj = obtenerLocal(id_Local);
		getHibernateTemplate().delete(obj);
		
	}

	public Local obtenerLocalxNombre(String nombre) {
		// TODO Auto-generated method stub
		return (Local) getSession().createQuery("from Local u where u.desc_Local=?").setString(0, nombre).uniqueResult();
		
	}

}
